package com.airsystem.pos.bengkel.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.ForeignKey;

/**
 * @author Budi Oktaviyan <budi.oktaviyan@icloud.com>
 */

@Entity
@Table(name = "tbl_detail_order_layanan")
public class DetailOrderLayanan implements Serializable {

	@Transient
	public static final String ALIAS = "detail_order_layanan";

	@Id
	@GeneratedValue
	public Long id;

	@ManyToOne
	@ForeignKey(name = "FK_ORDER_LAYANAN")
	private OrderLayanan order_layanan;

	@ManyToOne
	@ForeignKey(name = "FK_DETAIL_SPAREPART")
	private DetailSparepart detail_sparepart;

	@ManyToOne
	@ForeignKey(name = "FK_DETAIL_LAYANAN")
	private DetailLayanan detail_layanan;

	private String kilometer;

	private int sparepartTerpakai;

	private int metode;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public OrderLayanan getOrder_layanan() {
		return order_layanan;
	}

	public void setOrder_layanan(OrderLayanan order_layanan) {
		this.order_layanan = order_layanan;
	}

	public DetailSparepart getDetail_sparepart() {
		return detail_sparepart;
	}

	public void setDetail_sparepart(DetailSparepart detail_sparepart) {
		this.detail_sparepart = detail_sparepart;
	}

	public DetailLayanan getDetail_layanan() {
		return detail_layanan;
	}

	public void setDetail_layanan(DetailLayanan detail_layanan) {
		this.detail_layanan = detail_layanan;
	}

	public String getKilometer() {
		return kilometer;
	}

	public void setKilometer(String kilometer) {
		this.kilometer = kilometer;
	}

	public int getSparepartTerpakai() {
		return sparepartTerpakai;
	}

	public void setSparepartTerpakai(int sparepartTerpakai) {
		this.sparepartTerpakai = sparepartTerpakai;
	}

	public int getMetode() {
		return metode;
	}

	public String getMetode_s() {
		return Metode.get(metode).name();
	}

	public Metode getMetode_e() {
		return Metode.get(metode);
	}

	public void setMetode(String metode) {
		setMetode(Metode.get(metode));
	}

	public void setMetode(Metode metode) {
		this.metode = metode.getFlag();
	}

	public enum Metode {
		TUNAI(0),

		HUTANG_1_MINGGU(1),

		HUTANG_2_MINGGU(2),

		HUTANG_3_MINGGU(3),

		HUTANG_4_MINGGU(4),

		BOTH(5),

		UNKNOWN(-1);

		int flag;

		Metode(int flag) {
			this.flag = flag;
		}

		public int getFlag() {
			return flag;
		}

		public static Metode get(String metode) {
			for (Metode item : values()) {
				if (item.name().equalsIgnoreCase(metode.trim())) {
					return item;
				}
			}

			return UNKNOWN;
		}

		public static Metode get(int metode) {
			for (Metode item : values()) {
				if (item.getFlag() == metode) {
					return item;
				}
			}

			return UNKNOWN;
		}
	}
}